package com.github.skystardust.lotteryex.config;

import com.github.skystardust.lotteryex.lottery.bundle.LotteryBundle;
import com.github.skystardust.lotteryex.utils.MessageUtils;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;

import java.util.ArrayList;
import java.util.List;

public class RewardConfig extends ConfigBase {
    private List<LotteryBundle> lotteryItemList;

    public RewardConfig(String name, Plugin plugin) {
        super(name, plugin);
    }


    public void loadConfig() {
        this.lotteryItemList = new ArrayList<>();
        getFileConfiguration().getKeys(false).forEach(string -> {
            Object object = getFileConfiguration().get(string);
            if (!(object instanceof LotteryBundle)) {
                try {
                    throw new IllegalArgumentException();
                } catch (IllegalArgumentException e) {
                    new MessageUtils<>(Bukkit.getConsoleSender())
                            .warn("配置文件加载时发生严重错误!")
                            .warn("无法加载节点 §b" + string)
                            .warn("已为您自动跳过错误节点的加载!");
                }
            } else {
                lotteryItemList.add((LotteryBundle) object);
            }
        });

    }

    public List<LotteryBundle> getLotteryItemList() {
        return lotteryItemList;
    }

    public void setLotteryItemList(List<LotteryBundle> lotteryItemList) {
        this.lotteryItemList = lotteryItemList;
    }
}
